package com.handydata.antifraud.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

import com.handydata.antifraud.common.exception.OrderReturnInfoExCode;
import com.handydata.antifraud.bo.orderreturninfo.OrderReturnInfoReqBO;
import com.handydata.antifraud.bo.orderreturninfo.OrderReturnInfoResBO;
import com.handydata.antifraud.vo.orderreturninfo.CreateOrderReturnInfoReqVO;
import com.handydata.antifraud.vo.orderreturninfo.CreateOrderReturnInfoResVO;
import com.handydata.antifraud.vo.orderreturninfo.DeleteOrderReturnInfoReqVO;
import com.handydata.antifraud.vo.orderreturninfo.DeleteOrderReturnInfoResVO;
import com.handydata.antifraud.vo.orderreturninfo.ModifyOrderReturnInfoReqVO;
import com.handydata.antifraud.vo.orderreturninfo.ModifyOrderReturnInfoResVO;
import com.handydata.antifraud.vo.orderreturninfo.OrderReturnInfoBeanVO;
import com.handydata.antifraud.vo.orderreturninfo.QueryOrderReturnInfoReqVO;
import com.handydata.antifraud.vo.orderreturninfo.QueryOrderReturnInfoResVO;
import com.handydata.antifraud.service.OrderReturnInfoService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/orderreturninfo")
@RestController
public class OrderReturnInfoController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(OrderReturnInfoController.class);
	
	@Autowired
	private OrderReturnInfoService orderReturnInfoService;
	
	@ApiOperation(value="新增订单处理信息返回表", notes="新增订单处理信息返回表")
	@ApiImplicitParam(name = "req", value = "新增订单处理信息返回表请求对象", required = true, dataType = "CreateOrderReturnInfoReqVO", paramType = "body")
	@PostMapping("/create")
	public CreateOrderReturnInfoResVO createOrderReturnInfo(@RequestBody CreateOrderReturnInfoReqVO req) {
		try {
			logger.info("Execute createOrderReturnInfo, param is {}", req);
			OrderReturnInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderReturnInfoReqBO.class);
			OrderReturnInfoResBO resBO = orderReturnInfoService.createOrderReturnInfo(reqBO);
			CreateOrderReturnInfoResVO res = CommonBeanConvertor.convert(resBO, CreateOrderReturnInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateOrderReturnInfoResVO.class, req, OrderReturnInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改订单处理信息返回表", notes="修改订单处理信息返回表")
	@ApiImplicitParam(name = "req", value = "修改订单处理信息返回表请求对象", required = true, dataType = "ModifyOrderReturnInfoReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyOrderReturnInfoResVO modifyOrderReturnInfo(@RequestBody ModifyOrderReturnInfoReqVO req) {
		try {
			logger.info("Execute modifyOrderReturnInfo, param is {}", req);
			OrderReturnInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderReturnInfoReqBO.class);
			OrderReturnInfoResBO resBO = orderReturnInfoService.modifyOrderReturnInfo(reqBO);
			ModifyOrderReturnInfoResVO res = CommonBeanConvertor.convert(resBO, ModifyOrderReturnInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyOrderReturnInfoResVO.class, req, OrderReturnInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除订单处理信息返回表", notes="删除订单处理信息返回表")
	@ApiImplicitParam(name = "req", value = "修改订单处理信息返回表请求对象", required = true, dataType = "DeleteOrderReturnInfoReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeleteOrderReturnInfoResVO deleteOrderReturnInfo(@RequestBody DeleteOrderReturnInfoReqVO req) {
		try {
			logger.info("Execute deleteOrderReturnInfo, param is {}", req);
			OrderReturnInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderReturnInfoReqBO.class);
			OrderReturnInfoResBO resBO = orderReturnInfoService.deleteOrderReturnInfo(reqBO);
			DeleteOrderReturnInfoResVO res = CommonBeanConvertor.convert(resBO, DeleteOrderReturnInfoResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteOrderReturnInfoResVO.class, req, OrderReturnInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询订单处理信息返回表", notes="查询订单处理信息返回表")
	@ApiImplicitParam(name = "req", value = "查询订单处理信息返回表请求对象", required = true, dataType = "QueryOrderReturnInfoReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryOrderReturnInfoResVO queryOrderReturnInfo(@RequestBody QueryOrderReturnInfoReqVO req) {
		try {
			logger.info("Execute queryOrderReturnInfo, param is {}", req);
			OrderReturnInfoReqBO reqBO = CommonBeanConvertor.convert(req, OrderReturnInfoReqBO.class);
			OrderReturnInfoResBO resBO = orderReturnInfoService.queryOrderReturnInfo(reqBO);
			QueryOrderReturnInfoResVO res = CommonBeanConvertor.convert(resBO, QueryOrderReturnInfoResVO.class, OrderReturnInfoBeanVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, QueryOrderReturnInfoResVO.class, req, OrderReturnInfoExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
}
